<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class AdminUserModel extends Model
{
    use ValidatorModel;

    protected $table = 'admin_user';

    public static $rules = [
        'username'=>'required|alpha_num|max:10|min:4',
        'password' => 'required|alpha_dash|max:20|min:6|confirmed',
        'email' => 'email',
        'mobile' => 'required|digits:11',
    ];


    public function find($condition, $field)
    {
        return $this->where($condition)->select($field)->first()->toArray();
    }


    public function edit(array $condition , array $data)
    {
        $rules = $this->getRules($data);

        $error = $this->validator($data, $rules);

        if($error){
            throw new \Exception($error);
        }

        $this->where($condition)->update($data);
    }

}